package com.hellowx.qydcdev.controller;

import com.hellowx.qydcdev.entity.Address;
import com.hellowx.qydcdev.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created on 2022/1/7.
 *
 * @author Hello WX
 */
@Api(tags = "收货地址模块")
@RestController
@RequestMapping("/address")
public class AddressController {

    @Resource
    private AddressService addressService;

    @ApiOperation("通过顾客 id 查询收货地址")
    @GetMapping("/listByCustomerId")
    public ResponseEntity<List<Address>> listAddressByCustomerId(@RequestParam("customerId") Long customerId){
        List<Address> addressList =addressService.listAddressByCustomerId(customerId);
        return ResponseEntity.ok(addressList);
    }

    @ApiOperation("修改收货地址(按照主键修改)")
    @PostMapping("/modifyAddress")
    public ResponseEntity<String> saveOrUpdateAddress(@RequestBody Address address){
        String msg = addressService.saveOrUpdateAddress(address);
        return ResponseEntity.ok(msg);
    }
}
